/**
 * Applikationsutveckling i Java, 5DV135
 * HT12
 * Project
 * 
 * File: DatabaseHandlerTest.java
 * Description: A class for testing the 
 * nullInvader.Engine.DatabaseHandler.java class.
 * Date: 13 december 2012
 * 
 * cs-user: dv11rlm
 * @author Robert Lundström
 */
package nullInvader.Engine;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.sql.SQLException;

import nullInvader.Engine.DatabaseHandler;

import org.junit.BeforeClass;
import org.junit.Test;

public class DatabaseHandlerTest {

    private static DatabaseHandler db;

    @BeforeClass
    static public void setUp() {
	db = null;
	try {
	    /*
	     * just enter whatever host+path you want. if the server
	     * isn't on the localhost. Works as long as it don't take
	     * more than 5 seconds to establish connection or you have
	     * other settings than those specified in the
	     * DatabaseHandler.
	     */
	    db = new DatabaseHandler("localhost");
	} catch (ClassNotFoundException e) {
	    fail();
	}
    }

    @Test
    public void notNullTest() {
	assertNotNull(db);
    }

    @Test
    public void connectTest() {
	assertTrue(db.connectToDataBase());
    }

    @Test
    public void submitScoreTest() throws SQLException {
	db.submitScore("a", "map1", 6);

	assertEquals("6", db.getHighscore("map1")[1]);
    }

    @Test
    public void returnValueTest() {
	for (String s : db.getDataBaseResult()) {
	    assertTrue(s.length() > 0);
	}
    }

    @Test
    public void dropHighscoreData() throws SQLException {
	db.submitScore("a", "map1", 6);
	db.dropHighscoreList();
	for (String s : db.getDataBaseResult()) {
	    assertEquals(0, s.length());
	}
    }
}
